package com.leo.slice;

import com.leo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Slider;
import ohos.agp.utils.Color;

public class StartShowAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private com.lihang.ShadowLayout ShadowLayout;
    private Slider skbar_x;
    private Slider skbar_y;
    private Slider skbar_limit;
    private Slider skbar_corner;
    private int alpha;
    private Slider skbar_alpha;
    private int red;
    private Slider skbar_red;
    private int green;
    private Slider skbar_green;
    private int blue;
    private Slider skbar_blue;
    private Image tab_topShow;
    private Image tab_bottomShow;
    private Image tab_rightShow;
    private Image tab_leftShow;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_start_show);
        ShadowLayout = (com.lihang.ShadowLayout) findComponentById(ResourceTable.Id_ShadowLayout);
        skbar_x = (Slider) findComponentById(ResourceTable.Id_skbar_x);
        skbar_y = (Slider) findComponentById(ResourceTable.Id_skbar_y);
        skbar_limit = (Slider) findComponentById(ResourceTable.Id_skbar_limit);
        skbar_corner = (Slider) findComponentById(ResourceTable.Id_skbar_corner);
        skbar_alpha = (Slider) findComponentById(ResourceTable.Id_skbar_alpha);
        skbar_red = (Slider) findComponentById(ResourceTable.Id_skbar_red);
        skbar_green = (Slider) findComponentById(ResourceTable.Id_skbar_green);
        skbar_blue = (Slider) findComponentById(ResourceTable.Id_skbar_blue);
        tab_topShow = (Image) findComponentById(ResourceTable.Id_tab_topShow);
        tab_topShow.setClickedListener(this);
        tab_bottomShow = (Image) findComponentById(ResourceTable.Id_tab_bottomShow);
        tab_bottomShow.setClickedListener(this);
        tab_rightShow = (Image) findComponentById(ResourceTable.Id_tab_rightShow);
        tab_rightShow.setClickedListener(this);
        tab_leftShow = (Image) findComponentById(ResourceTable.Id_tab_leftShow);
        tab_leftShow.setClickedListener(this);


        skbar_corner.setMaxValue((int) (ShadowLayout.getCornerRadius() * 3));
        skbar_corner.setProgressValue((int) ShadowLayout.getCornerRadius());
        skbar_corner.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                ShadowLayout.setCornerRadius(i);
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_limit.setMaxValue((int) (ShadowLayout.getShadowLimit() * 3));
        skbar_limit.setProgressValue((int) ShadowLayout.getShadowLimit());
        skbar_limit.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                ShadowLayout.setShadowLimit(i);
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_x.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                ShadowLayout.setShadowOffsetX(i - 100);
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_y.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                ShadowLayout.setShadowOffsetY(i - 100);
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_alpha.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                alpha = i;
                ShadowLayout.setShadowColor(Color.argb(alpha, red, green, blue));
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_red.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                red = i;
                ShadowLayout.setShadowColor(Color.argb(alpha, red, green, blue));
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_green.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                green = i;
                ShadowLayout.setShadowColor(Color.argb(alpha, red, green, blue));
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });


        skbar_blue.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                blue = i;
                ShadowLayout.setShadowColor(Color.argb(alpha, red, green, blue));
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_tab_topShow:
                ShadowLayout.setShadowHiddenTop(select(tab_topShow));
                break;
            case ResourceTable.Id_tab_bottomShow:
                ShadowLayout.setShadowHiddenBottom(select(tab_bottomShow));
                break;
            case ResourceTable.Id_tab_leftShow:
                ShadowLayout.setShadowHiddenLeft(select(tab_leftShow));
                break;
            case ResourceTable.Id_tab_rightShow:
                ShadowLayout.setShadowHiddenRight(select(tab_rightShow));
                break;
        }
    }

    public boolean select(Image imageView) {
        if (imageView.isSelected()) {
            imageView.setSelected(false);
            return false;
        } else {
            imageView.setSelected(true);
            return true;
        }
    }
}
